/**
 * Created by CYT on 2017/10/10.
 */
var username;
var password;
var userId;
var actorId;

$('#myform').bootstrapValidator({
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
        loginName: {
            validators: {
                notEmpty: {
                    message: '登录账号不能为空！'
                },
                message: ' '
                /*stringLength: {
                    min: 2,
                    max: 1,
                    message: ''
                }*/
            }
        },
        password: {
            validators: {
                notEmpty: {
                    message: '登录密码不能为空！'
                }/*,
                stringLength: {
                    min: 2,
                    max: 1,
                    message: ''
                }*/
            }
        }
    }
}).on('success.form.bv', function (e) {
    e.preventDefault();
    username = $("#username").val();
    password = $("#password").val();
    $.ajax({
        url: "/coolprint/print_cyt/selectUser",
        type: "post",
        dataType: "json",
        //form里面不止一个这两个input，这样传到后台为null
        //data: $("#myform").serialize(),
        data: {
            /*json*/
            userName: username,
            userCode: password
        },
        success: function (data) {
            let info = data.ajaxInfo;
            if (info == "Success") {
                sessionStorage.setItem("userId", data.ajaxObject.userId);
                sessionStorage.setItem("actorId", data.ajaxObject.actorId);
                sessionStorage.setItem("userName", data.ajaxObject.userRealName);
                window.location.href = "http://localhost:8080/coolprint/workbench.html";
                /*弹框*/
            } else {
                alert("用户名或密码输入错误！请重新输入");
            }
            $('#myform').bootstrapValidator('disableSubmitButtons', false).bootstrapValidator('resetForm', true);
        }
    })
});


// $(document).ready(function () {
//     $("#LogIn").click(function () {
//         username = $("#username").val();
//         password = $("#password").val();
//
//     })
// });


